// import { Events } from './Events';
// import type { EventCallbackFunc } from './CallObject';
// import { PoolObject } from './Pool';

class EventObj {
	/**
	 * pool之所以不用于复杂对象，是因为复杂对象往往没有明确的release
	 * 其一比如玩家player，往往in closure而没有察觉
	 * 此时如果主动的release，会导致in closure的对象转移了，危害不可估量
	 * 所以这样的对象只有destroy，没有release!
	 * 其二这样的对象分配没有那么频繁，不需要提高效率
	 */
	constructor() {
		// super();
		// console.log("this.events",this.class_name())
		this.events = Events.createEvents('EventObj', this);
	}

	disablePool(): boolean {
		return true;
	}

	events: Events;

	on(event: string, func: EventCallbackFunc, self: unknown, tag: string): this {
		this.events.on(event, func, self, tag);
		return this;
	}

	once(event: string, func: EventCallbackFunc, self: unknown, tag: string): this {
		this.events.once(event, func, self, tag);
		return this;
	}

	onceUntil(
		event: string,
		listener: (...args: any[]) => boolean,
		self: unknown,
		tag: string,
	): this {
		this.events.onceUntil(event, listener, self, tag);
		return this;
	}

	emit(event: string, ...args: any[]): number {
		return this.events.emit(event, ...args);
	}

	removeListener(event: string, tag: string): boolean {
		return this.events.removeListener(event, tag);
	}

	removeTag(tag: string): boolean {
		return this.events.removeTag(tag);
	}

	private _destroyed = false;

	// override...
	destroy(): void {
		if (this.isDestroy()) {
			return;
		}
		this._destroyed = true;
		this.onDestroyed();
		// super.release();
	}

	onDestroyed(): void {
		this.events.release();
		this.events = null;
	}

	isDestroy(): boolean {
		return this._destroyed;
	}

	dump(running: boolean): void {
		this.events.dump(running);
	}
}
